<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		$("#soform").attr("action", lpath + "?pageNo=" + 1);

		$("#soform").submit();
	}
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<button type="button" onclick="addcontent()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增文章
			</button>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th width="10">序号</th>
					<th width="30%">文章标题</th>
					<th width="20%">所属栏目</th>
					<th width="20%">文章推荐位置</th>
					<th width="20%">操作</th>
				</tr>
			</thead>
			[#list pagination.list as content ]
			<tr>
				<td align="center">${content_index!}</td>
				<td align="center">${content.title!}</td>
				<td align="center">${content.channelName!}</td>
				<td align="center">[#list channels as channel][#if content.channelId??][#if content.channelId==channel.id]${channel.channelName!}[/#if][/#if][/#list]</td>

				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${content.id}','${content.title!}')">更改标题</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="del('${content.id}')">删除</button>
				</td>
			</tr>
			[/#list]
		</table>

		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>


	<!-- 新增的弹出页 -->
	<div id="addcontent" style="width: 500px; height: 300px; display: none;">
		<form id="addform" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="channelId" id="addchannelId" value="${channelid}">
			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro">文章推荐位置</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="" min="1" required="required" readonly="readonly" value="[#list channels as channel][#if channelid??][#if channelid==(channel.id?string)]${channel.channelName!}[/#if][/#if][/#list]">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">选择文章</label>
				<div class="col-sm-7">
					<select class="form-control" name="contentId" id="addcontentId" onchange="setTitle()">
						<option value="">请选择</option>
						[#list contents as content]
						<option value="${content.id}">${content.title!}</option>
						[/#list]
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro">确认文章标题</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="" min="1" required="required" name="title" id="addtitle">
				</div>
			</div>
			
			<div class="form-group" style="margin-top: 10px;">
				<div class="col-sm-offset-3 col-sm-10">
					<input id="addsubmit" onclick="subadd()" type="button" class="btn btn-default" value="提交" />
				</div>
			</div>
			
		</form>
	</div>

	<!-- 编辑的弹出页 -->
	<div id="editcontent" style="width: 500px; height: 100px; display: none;">
		<form id="editform" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" id="editid">
			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro">文章标题</label>
				<div class="col-sm-7">
					<input type="text" class="form-control" placeholder="" min="1" required="required" name="title" id="edittitle">
				</div>
			</div>

			<div class="form-group" style="margin-top: 10px;">
				<div class="col-sm-offset-2 col-sm-10">
					<input id="editsubmit" onclick="subedit()" type="button" class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>




</body>
</html>
<script type="text/javascript">
	function setTitle(){
		var contentid = $("#addcontentId").val();
		[#list contents as content]
			if(contentid == ${content.id}){
				$("#addtitle").val('${content.title}');
			}
		[/#list]
	}


	//展示新增窗口
	function addcontent() {
		dialog = art.dialog({
			title : "新增文章",
			lock : true,
			content : document.getElementById('addcontent')
		});
	}
	//删除
	function del(id) {//弹出警告框判断是否删除
		if (confirm('是否确认删除')) {
			$.ajax({
				url : '/recommend/content_del.do',
				type : 'get',
				dataType : 'json',
				data : {
					id : id
				},
				beforeSend : function() {
					art.dialog.tips("删除中...");
				},
				success : function(data) {
					if (data.success) {
						location.reload();
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		}
	}

	//打开编辑窗口
	function edit(id, titile) {
		$("#editid").val(id);
		$("#edittitle").val(titile);
	
		dialog = art.dialog({
			title : "修改文章标题",
			lock : true,
			content : document.getElementById('editcontent')
		});
	}
	//新增提交
	function subadd(){
	[#--提交之前 form 要手动进行验证--]
	
	var name = $("input[id='addtitle']").val();
	if (!name) {
		alert('文章标题必须填写!');
		return;
	}
	var adid = $("select[id='addcontentId']").val();
	if (!adid) {
		alert('请选择文章!');
		return;
	}
	
	art.dialog.post({
		url: "/recommend/content_save.do",
        data:$("#addform").serialize(),
        success: function(data){
            if(data.success){
                location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	
	}
	
	//编辑提交
	function subedit(){
	[#--提交之前 form 要手动进行验证--]
	
	var name = $("input[id='edittitle']").val();
	if (!name) {
		alert('文章标题必须填写!');
		return;
	}

	art.dialog.post({
		url: "/recommend/content_edit.do",
        data:$("#editform").serialize(),
        success: function(data){
            if(data.success){
                location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	}
	

</script>